// src/api/doctor.ts
import apiClient from "@/api";
import type { Doctor } from "@/type/doctor";

// 获取所有医生信息
export const getAllDoctors = (): Promise<Doctor[]> => {
  return apiClient.get("/doctor/getAllDoctor")
    .then(response => response.data)
    .catch(error => {
      console.error("获取所有医生信息失败:", error);
      throw error;
    });
};

// 获取单个医生信息
export const getDoctor = (doctorId: number): Promise<Doctor> => {
  return apiClient.get(`/doctor/${doctorId}`)
    .then(response => response.data)
    .catch(error => {
      console.error("获取医生信息失败:", error);
      throw error;
    });
};

// 更新医生信息
export const updateDoctor = (doctorId: number, doctorData: Doctor): Promise<Doctor> => {
  return apiClient.put(`/doctor/${doctorId}`, doctorData)
    .then(response => response.data)
    .catch(error => {
      console.error("更新医生信息失败:", error);
      throw error;
    });
};

// 添加新医生
export const addDoctor = (doctorData: Doctor): Promise<Doctor> => {
  return apiClient.post("/doctor", doctorData)
    .then(response => response.data)
    .catch(error => {
      console.error("添加医生失败:", error);
      throw error;
    });
};